package com.edu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.bean.Book;
import com.edu.service.BookService;
import com.edu.service.impl.BookServiceImpl;


@WebServlet("/searchBook.do")
public class SearchBookServlet extends HttpServlet {
	

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		Object u = request.getSession().getAttribute("loginUser");
		if(u == null){
				response.sendRedirect("login.jsp");
					return;
		}
		BookService bs = new BookServiceImpl();
		request.setCharacterEncoding("utf-8");
		String bookName = request.getParameter("bookName");
		List<Book> books = bs.getBookByName(bookName);
		request.setAttribute("books",books);
		request.getRequestDispatcher("book.jsp").forward(request, response);
	}

}
